﻿CREATE PROCEDURE [dbo].[proc_Customer_CallOnTongJi_CategoryView]
(
	@DepartmentId int,
	@StartDate nvarchar(10),
	@EndDate nvarchar(10),
	@StartIndex int,
	@EndIndex int
)
as
Begin
	;WITH list As (Select ROW_NUMBER() OVER (ORDER BY ct.UpTime DESC)AS Row,
		ct.Id,
		ct.CustomerId,
		ct.Record,
		ct.UpTime,
		ct.UpName,
		ct.IntentionsId,
		ct.PublicityDemandId,
		ct.NetworkConsciousnessId,
		ct.GenJinId,
		(Select EName From Employee Where UserName=ct.UpName) As EName,
		(Select CustomerName From Customer Where CustomerId=ct.CustomerId) as CustomerName,
		(Select Title From Customer_Intentions Where Id=ct.IntentionsId) as Intentions,
		(Select Phases From Customer_PublicityDemand Where Id=ct.PublicityDemandId) as PublicityDemand,
		(Select Title From Customer_NetworkConsciousness Where Id=ct.NetworkConsciousnessId) as NetworkConsciousness,
		(Select Title from Customer_genjin Where Id=ct.GenjinId) as GenJin
    From Customer_Track ct
	Where ct.DepartmentId=@DepartmentId and Convert(nchar(10),UpTime,120)>=@StartDate and Convert(nchar(10),UpTime,120)<=@EndDate and ct.PublicityDemandId <>0 and NetworkConsciousnessId<>0
	)
	--Select * From list Where Row between @StartIndex and @EndIndex
	Select *,(Select Count(0) From list) As RecordCount From list Where Row between @StartIndex and @EndIndex
End
